'''
Created on Jun 7, 2011

@author: peterd
'''

from django.forms import widgets
from django.forms.util import flatatt
from django.utils.safestring import mark_safe
from django.utils.encoding import force_unicode


class DirectionSelect(widgets.Select):
    def __init__(self, attrs=None, choices=()):
            super(DirectionSelect, self).__init__(attrs)
            
    def render(self, name, value, attrs=None, choices=()):
            if value is None: value = ''
            final_attrs = self.build_attrs(attrs, name=name)
            output = [u'<select%s onchange="updateDirection(this);">' % flatatt(final_attrs)]
            options = self.render_options(choices, [value])
            if options:
                    output.append(options)
            output.append(u'</select>')
            return mark_safe(u'\n'.join(output))
